﻿class Unit extends MovieClip
{
	private var unit_size:Number; // store the size of the unit (also usefull for movement size) - since the x & y are the same, this is just a convenient way to store both values as on var...
	
	//note!! - values are initialised via the attachmovieclip funciton in snake
	
	//unit is the base class for the head and body parts of the snake
	function Unit ()
	{
		//trace ("new Unit created"); // debug
		this._width = this._height = unit_size;
	}
	
	public function move_unit(dir:String):Void
	{
		//trace("unit move_unit called!");
		switch (dir)
		{
			case "up":
				//move this unit up
				this._y -= unit_size;
				if (this._y < 0)
				{
					//trace(this._y);
					this._y = Stage.height - unit_size; //padding to compensate for top left registration mark
				}
				break;
			case "down":
				//move this unit down
				this._y += unit_size;
				if (this._y > Stage.height - unit_size)
				{
					//trace("crossed boundary bottom");
					this._y = 0;
				}
				break;
			case "left":
				//move this unit left
				this._x -= unit_size;
				if (this._x < 0)
				{
					//trace("crossed boundary left");
					this._x = Stage.width - unit_size;
				}
				break;
			case "right":
				//move this unit right
				this._x += unit_size;
				if (this._x > Stage.width - unit_size)
				{
					//trace("crossed boundary right");
					this._x = 0;
				}
				break;
			default:
				//error
			//	trace ("staying still");
				break;
		}
	}
	public function get size():Number 
	{
		return (unit_size);
	}
}